﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Workbench.Properties;

namespace Contacts
{
	public partial class OpForm : Form
	{
		private ToolTip t1;
		private ToolTip TipforFirstLast;
		private ToolTip TipforLastFirst;
		private ToolTip Tipforcityfirst;
		private ToolTip Tipforstorefirst;

		public OpForm ()
		{
			InitializeComponent ();
			#region ToolTips
			t1 = new ToolTip ();
			t1.AutoPopDelay = 5000;
			t1.InitialDelay = 1000;
			t1.ReshowDelay = 500;
			t1.ShowAlways = true;
			t1.SetToolTip (this.TDelaybox, "Enter time in whole Minutes only.");
			
			TipforFirstLast = new ToolTip ();
			TipforFirstLast.AutoPopDelay = 5000;
			TipforFirstLast .InitialDelay = 1000;
			TipforFirstLast.ReshowDelay = 500;
			TipforFirstLast.ShowAlways = true;
			TipforFirstLast.SetToolTip (this.FirstLast, "Select to disply names formatted FirstName LastName");
			
			TipforLastFirst = new ToolTip ();
			TipforLastFirst.AutoPopDelay = 5000;
			TipforLastFirst .InitialDelay = 1000;
			TipforLastFirst.ReshowDelay = 500;
			TipforLastFirst.ShowAlways = true;
			TipforLastFirst.SetToolTip (this.LastFirst, "Select to disply names formatted LastName, FirstName");
			
			Tipforcityfirst = new ToolTip ();
			Tipforcityfirst.AutoPopDelay = 5000;
			Tipforcityfirst .InitialDelay = 1000;
			Tipforcityfirst.ReshowDelay = 500;
			Tipforcityfirst.ShowAlways = true;
			Tipforcityfirst.SetToolTip (this.cityfirst, "Select to disply names formatted FirstName LastName");
			
			Tipforstorefirst = new ToolTip ();
			Tipforstorefirst.AutoPopDelay = 5000;
			Tipforstorefirst .InitialDelay = 1000;
			Tipforstorefirst.ReshowDelay = 500;
			Tipforstorefirst.ShowAlways = true;
			Tipforstorefirst.SetToolTip (this.storefirst, "Select to disply names formatted FirstName LastName");
			#endregion
		}

		/// <summary>
		/// Establish default values based on the current user settings.
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void OpForm_Load(object sender, EventArgs e)
		{
			// fill the time interval
			TDelaybox.Text = Workbench.Properties.Settings.Default.TIME_ALIVE.ToString();

			//toggle radio button for name display
			if (Workbench.Properties.Settings.Default.DISPLAY_NAME_ORDER == "LAST")
			{
				FirstLast.Checked = false;
				LastFirst.Checked = true;
			}
			else
			{
				FirstLast.Checked = true;
				LastFirst.Checked = false;
			}
			//end name toggle

			// toggle radio buttons for store display
			if (Workbench.Properties.Settings.Default.STORE_SORT == "STORE")
			{
				storefirst.Checked = true;
				cityfirst.Checked = false;
			}
			else
			{
				storefirst.Checked = false;
				cityfirst.Checked = true;
			}
			// end store toggle

		}

		private void TDelaybox_TextChanged(object sender, EventArgs e)
		{
			try
			{
				Workbench.Properties.Settings.Default.TIME_ALIVE = int.Parse(TDelaybox.Text);
				el.Visible = false;
				Workbench.Properties.Settings.Default.Save();
			}
			catch (Exception)
			{
				
				el.ForeColor = Color.Red;
				el.Show();
				//throw;

			}

		}

		private void FirstLast_CheckedChanged(object sender, EventArgs e)
		{
			if(FirstLast.Checked) LastFirst.Checked = false;
			Workbench.Properties.Settings.Default.DISPLAY_NAME_ORDER = "FIRST";
			Workbench.Properties.Settings.Default.Save();
		}

		private void LastFirst_CheckedChanged(object sender, EventArgs e)
		{
			if (LastFirst.Checked) FirstLast.Checked = false;
			Workbench.Properties.Settings.Default.DISPLAY_NAME_ORDER = "LAST";
			Workbench.Properties.Settings.Default.Save();
		}

		private void cityfirst_CheckedChanged(object sender, EventArgs e)
		{
			if (cityfirst.Checked) storefirst.Checked = false;
			Workbench.Properties.Settings.Default.STORE_SORT = "CITY";
			Workbench.Properties.Settings.Default.Save();
		}

		private void storefirst_CheckedChanged(object sender, EventArgs e)
		{
			if (storefirst.Checked) cityfirst.Checked = false;
			Workbench.Properties.Settings.Default.STORE_SORT = "STORE";
			Workbench.Properties.Settings.Default.Save();
		}

		//TODO: add procedures here to either return proper values via properies
		//or via function calls directly to the dataset
		// Add a feature request form flyout
	}
}
